<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>03-自定义属性</title>
</head>
<body>
    <div id="demo" index1 = "1" class="nav">123456</div>
    <script>
        let div = document.querySelector('div');
        console.log(typeof div);  // object
        console.log(div); // <div id="demo" index1 = "1" class="nav">123456</div>

        // 1. 获取对象的自带属性
        console.log(div.id);  //demo
        console.log(div.class);  // undefined
        console.log(div.index1);  // undefined

        // 2. 设置获取自定义属性

        console.log(div.getAttribute('class'));   // nav
        console.log(div.getAttribute('index1'));   //  1
        
        div.setAttribute('index2','coco');    // 设置属性 添加属性值  键值对   就是对象    
        console.log(div);   // coco    <div id="demo" index1 = "1"  index2 = "coco" class="nav">123456</div>

        // console.log(div.getAttribute('id'));
        // div.setAttribute('id','coco');
        // console.log(div);


        // 3. 移除属性
        div.removeAttribute('class');
      
    </script>
</body>
</html>